using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    using System.Configuration;

    public partial class FrmMain : Form
    {
        Configuration _cfg ;
        public static string chuoiketnoi="123";
        public FrmMain()
        {
            InitializeComponent();

            _cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var a = _cfg.ConnectionStrings.ConnectionStrings[1];
            chuoiketnoi = a.ConnectionString;
        }

        private void dangNhapToolStripMenuItem_Click(object sender, EventArgs e)
        {
  

            var x = new Form1();
            //var x = new FrmNhanvien();
            x.MdiParent = this;
            x.Show();
            //DateTime.Now;
        }

        private void luuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                _cfg.ConnectionStrings.ConnectionStrings[1] = ConnectionStringSetting;
                _cfg.Save(ConfigurationSaveMode.Modified);

                ConfigurationManager.RefreshSection(_cfg.ConnectionStrings.SectionInformation.Name);
                Properties.Settings.Default.Reload();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private ConnectionStringSettings ConnectionStringSetting
        {
            get
            {
               

                var sver = "thanh-thao";
                var user = "sa";
                var pass = "123456";
                var data = "abc";
                var str = "";
              
                //if (cbbAuthen.Text == STR_WIND) str = String.Format(STR_TRU, sver, data);
                 str = String.Format(STR_SEC, sver, data, user, pass);

                _a.ConnectionString = str;
                return _a;
            }
        }
        private ConnectionStringSettings _a = new ConnectionStringSettings("xx", @"Data Source=.;Initial Catalog=xSKGv1;Integrated Security=True", "System.Data.SqlClient");

        public const string STR_SEC = @"Data Source={0};Initial Catalog={1};Persist Security Info=True;User Id={2};Password={3}";
        public const string STR_TRU = @"Data Source={0};Initial Catalog={1};Integrated Security=SSPI";

        private void khoaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var x = new FrmKhoa();
            x.MdiParent = this;
            x.Show();
        }
    }
}
